home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_windowmaker.idb / usr / freeware / include / wraster.h.z / wraster.h
Encoding:
C/C++ Source or Header  |  1999-07-16  |  9.9 KB  |  407 lines

  1. /*
  2.  *  Raster graphics library
  3.  * 
  4.  *  Copyright (c) 1997, 1998, 1999 Alfredo K. Kojima
  5.  * 
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *  
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *  
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * Environment variables:
  23.  * 
  24.  * WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
  25.  * gamma correction value. Must be  greater than 0
  26.  * Only for PseudoColor visuals.
  27.  * 
  28.  * Default:
  29.  * WRASTER_GAMMA 1/1/1
  30.  * 
  31.  * 
  32.  * If you want a specific value for a screen, append the screen number
  33.  * preceded by a hash to the variable name as in
  34.  * WRASTER_GAMMA#1
  35.  * for screen number 1
  36.  */
  37.  
  38. #ifndef RLRASTER_H_
  39. #define RLRASTER_H_
  40.  
  41.  
  42. /* version of the header for the library: 0.14 */
  43. #define WRASTER_HEADER_VERSION    14
  44.  
  45.  
  46. #include <X11/Xlib.h>
  47. #include <X11/Xutil.h>
  48.  
  49. #ifdef XSHM
  50. #include <X11/extensions/XShm.h>
  51. #endif
  52.  
  53. /* RM_MATCH or RM_DITHER */
  54. #define RC_RenderMode         (1<<0)
  55.  
  56. /* number of colors per channel for colormap in PseudoColor mode */
  57. #define RC_ColorsPerChannel    (1<<1)
  58.  
  59. /* do gamma correction */
  60. #define RC_GammaCorrection    (1<<2)
  61.  
  62. /* visual id to use */
  63. #define RC_VisualID        (1<<3)
  64.  
  65. /* shared memory usage */
  66. #define RC_UseSharedMemory    (1<<4)
  67.  
  68. /* use default instead of best visual */
  69. #define RC_DefaultVisual    (1<<5)
  70.  
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif /* __cplusplus */
  74.  
  75. typedef struct RContextAttributes {
  76.     int flags;
  77.     int render_mode;
  78.     int colors_per_channel;           /* for PseudoColor */
  79.     float rgamma;               /* gamma correction for red, */
  80.     float ggamma;               /* green, */
  81.     float bgamma;               /* and blue */
  82.     VisualID visualid;               /* visual ID to use */
  83.     int use_shared_memory;           /* True of False */
  84. } RContextAttributes;
  85.  
  86.  
  87. /*
  88.  * describes a screen in terms of depth, visual, number of colors
  89.  * we can use, if we should do dithering, and what colors to use for
  90.  * dithering.
  91.  */
  92. typedef struct RContext {
  93.     Display *dpy;
  94.     int screen_number;
  95.     Colormap cmap;
  96.     
  97.     RContextAttributes *attribs;
  98.  
  99.     GC copy_gc;
  100.  
  101.     Visual *visual;
  102.     int depth;
  103.     Window drawable;               /* window to pass for XCreatePixmap().*/
  104.                        /* generally = root */
  105.     int vclass;
  106.     
  107.     unsigned long black;
  108.     unsigned long white;
  109.     
  110.     int red_offset;               /* only used in 24bpp */
  111.     int green_offset;
  112.     int blue_offset;
  113.  
  114.     /* only used for pseudocolor and grayscale */
  115.  
  116.     XStandardColormap *std_rgb_map;    /* standard RGB colormap */
  117.     XStandardColormap *std_gray_map;   /* standard grayscale colormap */
  118.     
  119.     int ncolors;               /* total number of colors we can use */
  120.     XColor *colors;               /* internal colormap */
  121.  
  122.     struct {
  123.     unsigned int use_shared_pixmap:1;
  124.     } flags;
  125. } RContext;
  126.  
  127.  
  128. typedef struct RColor {
  129.     unsigned char red;
  130.     unsigned char green;
  131.     unsigned char blue;
  132.     unsigned char alpha;
  133. } RColor;
  134.  
  135.  
  136. typedef struct RHSVColor {
  137.     unsigned short hue;               /* 0-359 */
  138.     unsigned char saturation;           /* 0-255 */
  139.     unsigned char value;           /* 0-255 */
  140. } RHSVColor;
  141.  
  142.  
  143.  
  144. typedef struct RPoint {
  145.     int x, y;
  146. } RPoint;
  147.  
  148.  
  149. typedef struct RSegment {
  150.     int x1, y1, x2, y2;
  151. } RSegment;
  152.  
  153.  
  154. /*
  155.  * internal 24bit+alpha image representation
  156.  */
  157. typedef struct RImage {
  158.     unsigned width, height;           /* size of the image */
  159.     RColor background;               /* background color */
  160.     unsigned char *data[4];           /* image data (R,G,B,A) */
  161. } RImage;
  162.  
  163.  
  164. /*
  165.  * internal wrapper for XImage. Used for shm abstraction
  166.  */
  167. typedef struct RXImage {
  168.     XImage *image;
  169.  
  170.     /* Private data. Do not access */
  171. #ifdef XSHM
  172.     XShmSegmentInfo info;
  173.     char is_shared;
  174. #endif
  175. } RXImage;
  176.  
  177.  
  178. /* note that not all operations are supported in all functions */
  179. enum {
  180.     RClearOperation,               /* clear with 0 */
  181.     RCopyOperation,
  182.     RNormalOperation,           /* same as combine */
  183.     RAddOperation,
  184.     RSubtractOperation
  185. };
  186.  
  187.  
  188. /* image display modes */
  189. enum {
  190.     RDitheredRendering = 0,
  191.     RBestMatchRendering = 1
  192. };
  193.  
  194. /* bw compat */
  195. #define RM_DITHER RDitheredRendering
  196. #define RM_MATCH  RBestMatchRendering
  197.  
  198. enum {
  199.     RAbsoluteCoordinates = 0,
  200.     RRelativeCoordinates = 1
  201. };
  202.  
  203.  
  204. enum {
  205.     RSunkenBevel    = -1,
  206.     RRaisedBevel    = 1    
  207. };
  208. /* bw compat */
  209. #define RBEV_SUNKEN    RSunkenBevel
  210. /* 1 pixel wide */
  211. #define RBEV_RAISED    RRaisedBevel
  212. /* 1 pixel wide on top/left 2 on bottom/right */
  213. #define RBEV_RAISED2    2
  214. /* 2 pixel width */
  215. #define RBEV_RAISED3    3
  216.  
  217. enum {
  218.     RHorizontalGradient = 2,
  219.     RVerticalGradient = 3,
  220.     RDiagonalGradient = 4
  221. };
  222. /* for backwards compatibility */
  223. #define RGRD_HORIZONTAL  RHorizontalGradient
  224. #define RGRD_VERTICAL     RVerticalGradient
  225. #define RGRD_DIAGONAL    RDiagonalGradient
  226.  
  227.  
  228.  
  229. /* error codes */
  230. #define RERR_NONE        0
  231. #define RERR_OPEN         1      /* cant open file */
  232. #define RERR_READ        2      /* error reading from file */
  233. #define RERR_WRITE        3      /* error writing to file */
  234. #define RERR_NOMEMORY        4      /* out of memory */
  235. #define RERR_NOCOLOR        5      /* out of color cells */
  236. #define RERR_BADIMAGEFILE    6      /* image file is corrupted or invalid */
  237. #define RERR_BADFORMAT        7      /* image file format is unknown */
  238. #define RERR_BADINDEX        8      /* no such image index in file */
  239.  
  240. #define RERR_BADVISUALID    16     /* invalid visual ID requested for context */
  241.  
  242. #define RERR_XERROR        127    /* internal X error */
  243. #define RERR_INTERNAL        128    /* should not happen */
  244.  
  245.  
  246. /*
  247.  * Returns a NULL terminated array of strings containing the
  248.  * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
  249.  * Do not free the returned data.
  250.  */
  251. char **RSupportedFileFormats(void);
  252.  
  253.  
  254. char *RGetImageFileFormat(char *file);
  255.  
  256. /*
  257.  * Xlib contexts
  258.  */
  259. RContext *RCreateContext(Display *dpy, int screen_number,
  260.              RContextAttributes *attribs);
  261.  
  262. void RDestroyContext(RContext *context);
  263.  
  264. Bool RGetClosestXColor(RContext *context, RColor *color, XColor *retColor);
  265.  
  266. /*
  267.  * RImage creation
  268.  */
  269. RImage *RCreateImage(unsigned width, unsigned height, int alpha);
  270.  
  271. RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
  272.  
  273. RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
  274.                  Pixmap mask);
  275.  
  276. RImage *RLoadImage(RContext *context, char *file, int index);
  277.  
  278.  
  279. void RDestroyImage(RImage *image);
  280.  
  281. RImage *RGetImageFromXPMData(RContext *context, char **data);
  282.  
  283. /*
  284.  * RImage storing
  285.  */
  286. Bool RSaveImage(RImage *image, char *filename, char *format);
  287.  
  288. /*
  289.  * Area manipulation
  290.  */
  291. RImage *RCloneImage(RImage *image);
  292.  
  293. RImage *RGetSubImage(RImage *image, int x, int y, unsigned width, 
  294.              unsigned height);
  295.  
  296. void RCombineImageWithColor(RImage *image, RColor *color);
  297.  
  298. void RCombineImages(RImage *image, RImage *src);
  299.  
  300. void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
  301.          unsigned height, int dx, int dy);
  302.  
  303. void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
  304.  
  305. void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy, 
  306.                    unsigned width, unsigned height, int dx, int dy,
  307.                    int opaqueness);
  308.  
  309. RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
  310.  
  311. RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
  312.  
  313. RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
  314.                            RColor *color);
  315.  
  316. /*
  317.  * Drawing
  318.  */
  319. Bool RGetPixel(RImage *image, int x, int y, RColor *color);
  320.  
  321. void RPutPixel(RImage *image, int x, int y, RColor *color);
  322.  
  323. void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
  324.  
  325. void RPutPixels(RImage *image, RPoint *points, int npoints, int mode, 
  326.         RColor *color);
  327.  
  328. void ROperatePixels(RImage *image, int operation, RPoint *points, 
  329.             int npoints, int mode, RColor *color);
  330.  
  331. int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
  332.  
  333. int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
  334.          RColor *color);
  335.  
  336. void RDrawLines(RImage *image, RPoint *points, int npoints, int mode, 
  337.         RColor *color);
  338.  
  339. void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
  340.            int mode, RColor *color);
  341.  
  342. void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
  343.  
  344. void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
  345.               RColor *color);
  346.  
  347. /*
  348.  * Color convertion
  349.  */
  350. void RRGBtoHSV(RColor *color, RHSVColor *hsv);
  351. void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
  352.  
  353. /*
  354.  * Painting
  355.  */
  356. void RClearImage(RImage *image, RColor *color);
  357.  
  358. void RBevelImage(RImage *image, int bevel_type);
  359.  
  360. RImage *RRenderGradient(unsigned width, unsigned height, RColor *from, 
  361.             RColor *to, int style);
  362.  
  363.  
  364. RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, 
  365.                  int style);
  366.  
  367.  
  368.  
  369. /*
  370.  * Convertion into X Pixmaps
  371.  */
  372. int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
  373.  
  374. int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
  375.               Pixmap *mask, int threshold);
  376.  
  377.  
  378. /*
  379.  * misc. utilities
  380.  */
  381. RXImage *RCreateXImage(RContext *context, int depth,
  382.                unsigned width, unsigned height);
  383.  
  384. RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
  385.             unsigned width, unsigned height);
  386.  
  387. void RDestroyXImage(RContext *context, RXImage *ximage);
  388.  
  389. void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage, 
  390.         int src_x, int src_y, int dest_x, int dest_y,
  391.         unsigned width, unsigned height);
  392.     
  393. /* do not free the returned string! */
  394. const char *RMessageForError(int errorCode);
  395.  
  396. int RBlurImage(RImage *image);
  397.  
  398. /****** Global Variables *******/
  399.  
  400. extern int RErrorCode;
  401.  
  402. #ifdef __cplusplus
  403. }
  404. #endif /* __cplusplus */
  405.  
  406. #endif
  407.